#include <iostream>
#include <math.h>
#include "StopWatch.h"
#include "IPstoring.h"
using namespace std;
namespace Tentamen
{
	int Rfakultet(int i)
	{
		int x = 0;

		if (i <= 0)
		{
			x = 1;
		}
		else
		{
			x = i * Rfakultet(i - 1);
		}

		return x;
	}

	double Rsum(int i,double x)
	{
		double ans = 0;

		if (i == 0)
		{
			ans = 1;
		}

		else
		{
			ans = (pow(x,i) / Rfakultet(i)) + Rsum(i - 1, x);
		}

		return ans;
	}



	int Ifakultet(int i)
	{
		int x = 1;
		for (int j = i; j > 0; j--)
		{
			x = x * j;
		}

		return x;
	}

	double Isum(int i, double x)
	{
		double ans = 0;

		for (int j = i; j >= 0; j--)
		{
			ans += pow(x, j) / Ifakultet(j);
		}

		return ans;
	}

	void main3_1a(int i,double x)
	{
		CStopWatch w1;
		double timeR = 0;
		for (int i = 0; i < 5000; i++)
		{
			w1.startTimer();
			Rsum(i, x);
			w1.stopTimer();
			timeR += w1.getElapsedTime();
		}
		cout << "Rekursiv tid: " << timeR / 5000 << "s" << endl;
	}

	void main3_1b(int i,double x)
	{	
		CStopWatch w2;
		double timeI = 0;
		for (int i = 0; i < 5000; i++)
		{
			w2.startTimer();
			Isum(i, x);
			w2.stopTimer();
			timeI += w2.getElapsedTime();
		}
		cout << "Iterativ tid: " << timeI / 5000 << "s" << endl;
	}

	void main3_2()
	{
		IPstoring ip;
		ip.ReadIPs("ip_one.txt");
		ip.AntalUppkopplingar("171.148.101.144");
		ip.TioMestFrekventa();
	}

}

int main()
{
	Tentamen::main3_1a(3,2);
	cout << endl;
	Tentamen::main3_1b(3,2);
	cout << endl << endl;
	Tentamen::main3_2();

	cout << endl << endl;
	system("pause");

}